package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.SelfAmmunition;
import com.sc.nft.entity.vo.SelfAmmunitionDetailVO;
import com.sc.nft.entity.vo.SelfAmmunitionPageVO;
import com.sc.nft.entity.vo.SelfAmmunitionVO;
import com.sc.nft.enums.JumpTypeEnum;
import com.sc.nft.mapper.SelfAmmunitionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Slf4j
@Repository
public class SelfAmmunitionDao extends ServiceImpl<SelfAmmunitionMapper, SelfAmmunition> {
    /**
     * 校验名称是否存在
     * @param selfAmmunitionName
     * @param jumpType
     * @param id
     * @return
     */
    public Integer checkSelfAmmunitionSelfAmmunitionName(String selfAmmunitionName, Integer jumpType, Long id) {
        return baseMapper.checkSelfAmmunitionSelfAmmunitionName(selfAmmunitionName,jumpType,id);
    }

    /**
     * 修改自弹
     * @param selfAmmunition
     * @return
     */
    public boolean selfAmmunitionUpdate(SelfAmmunition selfAmmunition) {
        LambdaUpdateWrapper<SelfAmmunition> wrapper = Wrappers.lambdaUpdate();
        wrapper.eq(SelfAmmunition::getId,selfAmmunition.getId());
        wrapper.set(SelfAmmunition::getActivityId,selfAmmunition.getActivityId());
        wrapper.set(SelfAmmunition::getSelfAmmunitionImg,selfAmmunition.getSelfAmmunitionImg());
        wrapper.set(SelfAmmunition::getSelfAmmunitionName,selfAmmunition.getSelfAmmunitionName());
        wrapper.set(SelfAmmunition::getJumpType,selfAmmunition.getJumpType());
        wrapper.set(SelfAmmunition::getJumpUrl,selfAmmunition.getJumpUrl());
        wrapper.set(SelfAmmunition::getJumpId,selfAmmunition.getJumpId());
        wrapper.set(SelfAmmunition::getRemark,selfAmmunition.getRemark());
        wrapper.set(SelfAmmunition::getSelfAmmunitionStartTime,selfAmmunition.getSelfAmmunitionStartTime());
        wrapper.set(SelfAmmunition::getSelfAmmunitionEndTime,selfAmmunition.getSelfAmmunitionEndTime());
        wrapper.set(SelfAmmunition::getSort,selfAmmunition.getSort());
        wrapper.set(SelfAmmunition::getSelfType,selfAmmunition.getSelfType());
        wrapper.set(SelfAmmunition::getRichText,selfAmmunition.getRichText());
        return update(new SelfAmmunition(),wrapper);
    }

    /**
     * 获取自弹列表
     * @param mp
     * @return
     */
    public IPage<SelfAmmunitionPageVO> selfAmmunitionPage(Page mp) {
        return baseMapper.selfAmmunitionPage(mp);
    }

    /**
     * 删除自弹
     * @param id
     * @return
     */
    public boolean selfAmmunitionDelete(Long id) {
        LambdaUpdateWrapper<SelfAmmunition> wrapper = Wrappers.lambdaUpdate();
        wrapper.eq(SelfAmmunition::getId, id);
        return remove(wrapper);
    }

    /**
     * 自弹上下架
     * @param id
     * @param status
     * @return
     */
    public boolean selfAmmunitionIsListing(Long id, Boolean status) {
        LambdaUpdateWrapper<SelfAmmunition> wrapper = Wrappers.lambdaUpdate();
        wrapper.set(SelfAmmunition::getIsListing, status);
        wrapper.eq(SelfAmmunition::getId, id);
        wrapper.eq(SelfAmmunition::getIsDelete, Boolean.FALSE);
        return update(new SelfAmmunition(),wrapper);
    }

    /**
     * 判断上架是否超过五个
     * @return
     */
    public Integer checkSelfAmmunitionIsListing() {
        return baseMapper.checkSelfAmmunitionIsListing();
    }

    /**
     * 保存展示的引导图到redis 五个
     * @return
     */
    public List<SelfAmmunitionVO> getSelfAmmunitionIsListing() {
        return baseMapper.getSelfAmmunitionIsListing();
    }


    /**
     * 获取引导图详情
     * @param id
     * @return
     */
    public SelfAmmunitionDetailVO selfAmmunitionDetail(Long id) {
        return baseMapper.selfAmmunitionDetail(id);
    }
}
